---
title: ApplicationDataAccess
summary: API reference for ApplicationDataAccess.
status: draft
owner: SAIF Documentation
last_reviewed: 2026-08-21
library: SAIF.Application
reference_type: embedded
---

# ApplicationDataAccess

`ApplicationDataAccess` is the data-portal provisioning boundary used by `AppManagerBase.DataLayer`: it builds `clsSQLDataPortal` / `clsMSOracleDataPortal` instances from plain connection properties (`DBUser`, `Database`, `Server`) and registers them in a keyed `IDataPortalInfo` registry, so a single manager can address multiple databases by name without any manager code composing or issuing SQL itself.

## Purpose
- Provisions Oracle or SQL Server data portals ([BR-APP-007](../../business-rules.md#br-app-007-database-client-identity-is-the-requesting-user-unless-overridden), [BR-APP-008](../../business-rules.md#br-app-008-a-dpi-key-is-bound-to-exactly-one-portal)) from connection properties supplied by the caller.
- Attributes the database session to the authenticated user by default, while allowing a batch process to substitute a service identity via `BatchID` ([BR-APP-007](../../business-rules.md#br-app-007-database-client-identity-is-the-requesting-user-unless-overridden)).
- Guards the portal registry so that only `AppManagerBase.InjectDPI` (same assembly) can register a handle from outside this class itself.

## Context
- Namespace: `SAIF.Application`
- Assembly/package: `SAIF.Application` (embedded, ProjectReference)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| `New` | `Public Sub New(Optional inBatchUserID As String = "")` | Creates the underlying `clsDataAccess` and `clsEnvironment`; a non-blank batch user id becomes the DAL client id, otherwise the DAL's own client id is used. |
| `DBUser` | `Public Property String` | DB user portion of the connection environment used when building either portal type. |
| `Database` | `Public Property String` | Database/service name portion of the connection environment. |
| `Server` | `Public Property String` | Server portion of the connection environment, used only by `CreateSQLServerPortal`. |
| `BatchID` | `Public Property String` | Overrides the environment `ClientID` when non-blank, letting a batch process substitute a service identity for the authenticated user ([BR-APP-007](../../business-rules.md#br-app-007-database-client-identity-is-the-requesting-user-unless-overridden)). |
| `DAL` | `Public ReadOnly Property As IDataAccess` | Exposes the underlying data-access object to the owning manager. |
| `DPI(inKey)` | `Public Property (get) / Friend Set` | Keyed registry of `IDataPortalInfo` handles; keys are lower-cased. The setter is `Friend`, so only this assembly (via `AppManagerBase.InjectDPI`) can register a handle from outside this class. |
| `CreateSQLServerPortal` | `Public Sub (inKey As String)` | Builds a `clsSQLDataPortal` from the current environment properties, sets `DBMSType` to `SqlServer`, and registers the returned DPI under `inKey` ([BR-APP-008](../../business-rules.md#br-app-008-a-dpi-key-is-bound-to-exactly-one-portal)). |
| `CreateOraclePortal` | `Public Sub (inKey As String)` | Builds a `clsMSOracleDataPortal` from the current environment properties, sets `DBMSType` to `Oracle`, and registers the returned DPI under `inKey` ([BR-APP-008](../../business-rules.md#br-app-008-a-dpi-key-is-bound-to-exactly-one-portal)). |

## Behavioral notes
- `ClientID` is seeded from the DAL's client id, then overwritten with `BatchID` when `BatchID.Trim.Length > 0` ([BR-APP-007](../../business-rules.md#br-app-007-database-client-identity-is-the-requesting-user-unless-overridden)).
- Re-using a key through `CreateOraclePortal` / `CreateSQLServerPortal` raises an `ArgumentException` (`SortedList.Add` semantics), while re-registering the same key through the `DPI` setter (i.e. via `InjectDPI`) is silently ignored — the first registration wins ([BR-APP-008](../../business-rules.md#br-app-008-a-dpi-key-is-bound-to-exactly-one-portal)).
- `m_DAL`, `m_Env`, and `m_DPILibrary` are `<NonSerialized()>`, so a deserialized instance retains only the connection strings/ids and must be re-initialized before portal creation.*
- No SQL is authored or issued anywhere in this type — it only establishes connection context for the business layer that later holds the portal handle.

## Constraints and usage notes
- The `BatchID` property has no guard and is freely settable by any caller; this is an impersonation-for-auditing mechanism only and does not affect AD authorization.
- External callers cannot register a DPI handle directly through the `DPI` setter (it is `Friend`); they must go through `CreateOraclePortal` / `CreateSQLServerPortal`, or through a derived manager's `InjectDPI` call.

> **Note:** Statements marked with `*` were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with `**` could not be confirmed; treat as unknown until verified.

## Sources
- `SAIF.Application/ApplicationDataAccess.vb`
- `SAIF.Application/AppManagerBase.vb`
